package net.mikoo.seals.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import net.mikoo.seals.common.exception.ParametersException;

public class Workflow extends BaseModel {

	private static final long serialVersionUID = 7090671103072825893L;

	/**
	 * ID
	 */
	private Long workflowId;

	private Long parentId;

	/**
	 * 所属公司ID
	 */
	private Long companyId;

	/**
	 * 流程类型
	 */
	private String workflowType;

	/**
	 * 流程名称
	 */
	private String name;

	/**
	 * 流程描述
	 */
	private String description;

	/**
	 * 是否启用
	 */
	private String isEnable;

	private String workflowStatus;
	
	private String auditor;

	/**
	 * 创建时间
	 */
	private Date createTime;

	private List<WorkflowSetting> settings;
	
	private String settingStr;

	public Long getWorkflowId() {
		return workflowId;
	}

	public void setWorkflowId(Long workflowId) {
		this.workflowId = workflowId;
	}

	public Long getCompanyId() {
		return companyId;
	}

	public void setCompanyId(Long companyId) {
		this.companyId = companyId;
	}

	public String getWorkflowType() {
		return workflowType;
	}

	public void setWorkflowType(String workflowType) {
		this.workflowType = workflowType;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getIsEnable() {
		return isEnable;
	}

	public void setIsEnable(String isEnable) {
		this.isEnable = isEnable;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public List<WorkflowSetting> getSettings() {
		
		
		if(StringUtils.isNotBlank(settingStr) ) {
			if(settingStr.indexOf(",")>=0 || settingStr.indexOf("|")>=0) {
				String  strArray[] = settingStr.split(",");
				if(strArray.length <=0 ) {
					return settings;
				}
				
				try {
					
					List<WorkflowSetting> settinglist =  new ArrayList<>();
					
					for (String str : strArray) {
						String settingArray[] = str.split("\\|");
						
						WorkflowSetting setting = new WorkflowSetting();
						setting.setPartyId(Long.parseLong(settingArray[0]));
						setting.setSequence(Integer.parseInt(settingArray[1]));
						settinglist.add(setting);
					}
					
					return settinglist;
					
				}catch (Exception e) {
					throw new ParametersException("非法参数请求");
				}
			}else if(settingStr.indexOf(";")>=0) {
				String  strArray[] = settingStr.split(";");
				if(strArray.length <=0 ) {
					return settings;
				}
				
				try {
					List<WorkflowSetting> settinglist =  new ArrayList<>();
					for (int i = 0; i < strArray.length; i++) {
						String str = strArray[i];
						
						WorkflowSetting setting = new WorkflowSetting();
						setting.setPartyId(Long.parseLong(str));
						setting.setSequence(i);
						settinglist.add(setting);
					}
					
					return settinglist;
					
				}catch (Exception e) {
					throw new ParametersException("非法参数请求");
				}
				
				
			}
			
		}
		
		return settings;
	}

	public void setSettings(List<WorkflowSetting> settings) {
		this.settings = settings;
	}

	public String getWorkflowStatus() {
		return workflowStatus;
	}

	public void setWorkflowStatus(String workflowStatus) {
		this.workflowStatus = workflowStatus;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public String getAuditor() {
		return auditor;
	}

	public void setAuditor(String auditor) {
		this.auditor = auditor;
	}

	public String getSettingStr() {
		return settingStr;
	}

	public void setSettingStr(String settingStr) {
		this.settingStr = settingStr;
	}
	
	

}